package org.testis.webautomationmodule.ui.objects;

import org.testis.logging.AtofLogLevel;
import org.testis.webautomationmodule.ui.UIBehaviorDecorator;


/**
 *
 * @author nurhat
 */
public class UIPopupClosed extends UIBehaviorDecorator
{

    public UIPopupClosed()
    {
    }


    @Override
    protected boolean setBehavior()
    {
        String previousWindow = getWebAutomationImpl().previousWindowIds.pop();
        if (previousWindow != null) {
            putLog("Closing popup and returning to window with id " +
                   previousWindow);
            String[] previousFramePath =
                getWebAutomationImpl().previousFramePaths.get(previousWindow);
            getWebAutomationImpl().previousFramePaths.remove(previousWindow);
            UIWindow win = new UIWindow(previousWindow);
            UIFrame frm = null;
            if (previousFramePath != null) {
                frm = new UIFrame(previousFramePath);
                frm.setWebAutomationImpl(getWebAutomationImpl());
                frm.setMessageId(getMessageId());
            }
            win.setWebAutomationImpl(getWebAutomationImpl());
            win.setMessageId(getMessageId());
            win.setNextUIObjectDecorator(frm);
            win.operate();
            return true;
        }
        else {
            putLog("Could not  return to previous window. " +
                   "previous window id not found",AtofLogLevel.ERROR);
            return false;
        }
    }
}
